package pl.edu.mimuw.mas.agent.behaviour.hunting.hunter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import pl.edu.mimuw.mas.agent.HunterAgent;
import pl.edu.mimuw.mas.agent.behaviour.ServerBehaviour;

public class ShootSynchronizationServerBehaviour extends ServerBehaviour {

	private static final long serialVersionUID = 3353767010914472077L;
	
	protected final Logger logger = LoggerFactory.getLogger(getClass());

	public ShootSynchronizationServerBehaviour(HunterAgent agent) {
		super(agent);
		
		MessageTemplate mt = MessageTemplate.and(
				MessageTemplate.MatchConversationId(HunterAgent.SHOOT_INFO_CONV),
				MessageTemplate.MatchPerformative(ACLMessage.INFORM)
				);
		setMessageTemplate(mt);
	}

	@Override
	public boolean doAction(ACLMessage msg, ACLMessage reply) {
		HunterAgent a = (HunterAgent) myAgent;
		
		logger.debug("{} : dostałem info o strzale od {}", a.getName(), msg.getSender().getName());
		
		a.setLastShooter(msg.getSender());
		a.setLastShootTime(System.currentTimeMillis());
		
		return false;
	}

}
